package com.ctshk.rpc.order.hotel.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ctshk.rpc.order.hotel.entity.HotelOrder;
import com.ctshk.rpc.order.hotel.req.HotelOrderPageReq;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 酒店订单表 Mapper 接口
 * </p>
 *
 * @author yinhuan
 * @since 2021-03-08
 */
public interface HotelOrderMapper extends BaseMapper<HotelOrder> {
    @Select("<script>"+
            "SELECT o.*" +
            " FROM t_hotel_order o \n" +
            "WHERE o.is_deleted = 0"+
            "<if test=\"req.orderNumber != null and req.orderNumber != ''\">AND o.order_number LIKE CONCAT('%',#{req.orderNumber},'%')</if> \n" +
            "<if test=\"req.cityName != null and req.cityName != 0\">AND o.city_name = #{req.cityName}</if> \n" +
            "<if test=\"req.brandName != null and req.brandName != ''\">AND o.brand_name LIKE CONCAT('%',#{req.brandName},'%')</if> \n" +
            "<if test=\"req.hotelName != null and req.hotelName != ''\">AND o.hotel_name LIKE CONCAT('%',#{req.hotelName},'%')</if> \n" +
            "<if test=\"req.roomName != null and req.roomName != ''\">AND o.room_name LIKE CONCAT('%',#{req.roomName},'%')</if> \n" +
            "<if test=\"req.scheduledStatus != null and req.scheduledStatus != ''\">AND o.scheduled_status =#{req.scheduledStatus}</if> \n" +
            "<if test=\"req.paymentStatus != null and req.paymentStatus != ''\">AND o.payment_status =#{req.paymentStatus}</if> \n" +
            "<if test=\"req.beginDate != null and req.endDate != null\">AND DATE_FORMAT(o.gmt_create,'%Y-%m-%d') between #{req.beginDate} and #{req.endDate}</if> \n" +
            "<if test=\"req.contactName != null and req.contactName != ''\">AND o.contact_name LIKE CONCAT('%',#{req.contactName},'%')</if> \n" +
            "<if test=\"req.productType != null\">AND o.product_type = #{req.productType}</if> \n" +
            "<if test=\"req.source != null\">AND o.source = #{req.source}</if> \n" +
            "<if test=\"req.salesmanName != null and req.salesmanName != ''\">AND o.salesman_name LIKE CONCAT('%',#{req.salesmanName},'%')</if> \n" +
            "AND create_id IN <foreach collection='ids' item='id' open='(' separator=',' close=')'> #{id} </foreach>" +
            "order by  o.gmt_create desc "+
            "</script>")
    IPage<HotelOrder> queryList(@Param("req") HotelOrderPageReq req, IPage<HotelOrder> agentPage, List<Long> ids);
}
